package com.lfm.jdbc.statement_;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Map;
import java.util.Properties;
import java.util.Scanner;

@SuppressWarnings({"all"})
public class Statement_ {
    public static void main(String[] args) throws Exception{

        String admin_name = "";
        String admin_pwd = "";

        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入管理员名字: ");
        admin_name = scanner.nextLine();
        System.out.print("请输入管理员密码: ");
        admin_pwd = scanner.nextLine();


        Properties properties = new Properties();
        properties.load(new FileInputStream("mariadb.properties"));

        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String driver = properties.getProperty("driver");
        String url = properties.getProperty("url");

        Class.forName(driver);

        Connection connection = DriverManager.getConnection(url, user, password);
        Statement statement = connection.createStatement();

        String sql = "select name, pwd " + "from admin where name = '" + admin_name + "' and pwd ='" + admin_pwd + "'";
        ResultSet resultSet = statement.executeQuery(sql);

        if (resultSet.next()) {
            System.out.println("成功");
        } else {
            System.out.println("失败");
        }

        resultSet.close();
        connection.close();
        statement.close();

    }

}
